﻿@{
    ViewBag.Title = "touzi";
    Layout = "~/Views/Shared/MasterView.cshtml";
    var memloanid = Session["memloanid"];
}

<script type="text/javascript" src="~/_files/jquery-1.8.3.min.js"> </script>
<script type="text/javascript" src="~/_files/jquery.validate.min.js"> </script>
<script type="text/javascript" src="~/Content/ReceptionView/scripts/legacy/JqueryJson.js"></script>
<script type="text/javascript" src="~/_files/com.js?t=201412"></script>
<script type="text/javascript" src="~/_files/jQuery.md5.js"></script>
<script type="text/javascript" src="~/_files/area.js"></script>
<script type="text/javascript" src="~/_files/ceng.js?t=201412"></script>
<script type="text/javascript" src="~/_files/hongling-validate-methods.js"></script>
<link type="text/css" rel="stylesheet" href="https://style.my089.com/pc/themes/base.css?t=20170104">
<link type="text/css" rel="stylesheet" href="https://style.my089.com/pc/themes/ceng.css?t=20170104">
<script type="text/javascript" src="~/_files/jPages.min.js"></script>
<script type="text/javascript" src="~/_files/util.js"></script>
<link rel="stylesheet" type="text/css" href="https://style.my089.com/pc/themes/util.css" />
<script type="text/javascript" src="~/Content/ReceptionView/scripts/common/jquery-jtemplates.js"></script>
<link type="text/css" rel="stylesheet" href="https://style.my089.com/pc/themes/Loan.css?t=20160104">
<script type="text/javascript">

    $(function () {
        var memloanids=@memloanid
        $.ajax({
            url: "/Invest/touzi_show",
            type:"post",
            data:{memid: memloanids},
            success:function (data) {
                $("#tas").html(data);
            }
        });
    });
    //进行投资
    function touziint_get() {
        //判断投标金额不能空
        var bidAmt = $('#txtBidAmt').val();
        var ketou=$("#ketoufanwei").val();
        if (bidAmt == "") {
            Util.window.Alert("投标金额不能为空！");
            return;
        };
        //判断输入格式
        if (!(/^[0-9]+$/.test(bidAmt.replace(/,/g, "")))) {
            Util.window.Alert("请填写正确的投标金额,不能有小数！");
            return;
        };
        //输入的金额不能小于五十
        if (bidAmt<50) {
            Util.window.Alert("投资金额不能小于50！");
            return;
        };
        if (bidAmt>parseFloat(ketou)) {
            Util.window.Alert("已超出可投范围！");
            return;
        }
        //判断用户输入的金额是否大于账户可用金额和输入的金额不能大于借款金额
        $.ajax({
            url:"/Invest/User_Select_TouZiRen_Money",
            type:"post",
            success:function (msg) 
            {
                if  (msg>=parseFloat( bidAmt))
                {
                    var d = new Date();
                    var dangqiantime = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
                    //alert("当前时间："+dangqiantime);
                    //alert("借款ID"+$("#MemLoanID").val());
                    $.ajax({
                        url:"/Invest/TouZi_Gets",
                        type:"post",
                        data:{
                            Userid:1,//投资人的ID，，也就是当前
                            TouZiJinMoney:$("#txtBidAmt").val(),
                            TouZiLiXi:$("#TouZiLiLv").val(),
                            TouBiaoTime:dangqiantime,
                            Memloanid:$("#MemLoanID").val()
                        },
                        success:function (data) {
                            if (data!==-1) {
                                alert   ("投资成功",location.href='/Invest/Invest_Show');
                                
                            }else {
                                alert("投资失败", location.href = '/MyAccount/View_UserLogin');
                            };
                        }
                    });
                }else {
                    //账户余额不足提示
                    Util.window.Alert("您的余额不足！");
                };
            }
        });
    };

    $(function () {
        changeImg();
        $('#txtBidAmt').keyup(function () {
            var DaXie = Chinese($('#txtBidAmt').val().replace(/ /g, ''));
            $("#spanDaXieAmount").text(DaXie);
        });
    });

    function setMaxAmt(amt) {
        var money = $('#remainderamt').html().replace(/,/g, '');
        var remainderamt_temp = money.substring(0, money.indexOf('.'));
        //$('#txtBidAmt').val($('#remainderamt').html().replace(/,/g,''));
        $('#txtBidAmt').val(remainderamt_temp);
        var DaXie = Chinese($('#txtBidAmt').val().replace(/ /g, ''));
        $("#spanDaXieAmount").text(DaXie);
    };
    //不启用
    function onSubmit() {
        var bidAmt = $('#txtBidAmt').val();
        if (bidAmt == "") {
            Util.window.Alert("投标金额不能为空！");
            return;
        }

        //        if(!(/^[0-9]+(.[0-9]{2})?$/.test(bidAmt.replace(/,/g, "")))&&!(/^[0-9]+(.[0-9]{1})?$/.test(bidAmt.replace(/,/g, "")))){
        //            Util.window.Alert("请填写正确的投标金额,小数最多保留两位！");
        //            return;
        //        }
        if (!(/^[0-9]+$/.test(bidAmt.replace(/,/g, "")))) {
            Util.window.Alert("请填写正确的投标金额,不能有小数！");
            return;
        }
        if (false) {
            Util.window.Confirm('注意：当前借款人已被您拉到黑名单中，您确定要投标吗？', function () {
                $("#onBiddingSubmitForm").submit();
            }, function () {
                document.location.href = '/credit/forBidding?sid=' + $("#hdnSID").val();
            }, "温馨提示");
        } else {
            $("#onBiddingSubmitForm").submit();
        }

    };

    function getAmt() {
        $.ajax({
            type: "post",
            url: "/credit/bid/tipForAccount",
            data: {
                SID: $.trim($("#hdnSID").val())
            },
            dataType: 'json',
            success: function (data) {
                if (data.success == true) {
                    $('#uamt').html(data.data["amount"]);
                    $('#remainderamt').html(data.data["remainderBidAmount"]);
                    enBtn();
                } else {

                }
            }
        });
    };

    function enBtn() {
        var amt = parseFloat($('#uamt').text().replace(/,/g, ""));
        var btn = $('#btnBid');
        if (amt > 0) {
            btn.removeAttr("disabled");
            btn.val('确认无误，投标');
        }
        else {
            btn.attr('disabled', 'disabled');
            btn.val('余额不足，不可投标');
        }
    };

    function changeImg() {
        $("#keyimage").click(function (event) {
            var date = new Date().toString();
            var rndId = $("#randomPageId").val();
            $("#keyimage").attr("src", "/debit/generateImageCode?randomPageId=" + rndId + "&date=" + date);
        });
    };

    function isShowRateTip() {
        if (false) {
            Util.window.Alert("您当前要投资的标的利率偏低，请注意确认再投标！");
        }
    };

    isShowRateTip();

</script>
<div id="tas" class="hdivBid" style=" width:900px; margin:0 auto;">
</div>
